package 笔试.同行者实习;

import java.util.ArrayList;
import java.util.List;

public class 字母组合 {
    public static void main(String[] args) {
        System.out.println(findAllSeq());
    }

    public static List<String> findAllSeq() {
        StringBuilder cur = new StringBuilder();
        ArrayList<String> res = new ArrayList<>();
        int index = 0;
        backtracing(cur, res, index);
        return res;
    }

    private static void backtracing(StringBuilder cur, ArrayList<String> res, int index) {
        if (index == 26 || cur.length() > 3) { // 限定最大长度为3
            return;
        }
        if (cur.length() != 0) {
            res.add(cur.toString());
        }
        for (int i = index; i < 26; i++) {
            cur.append((char) ('a' + i));
            backtracing(cur, res, i + 1);
            cur.deleteCharAt(cur.length() - 1);
        }
    }
}
